package com.wlcj.www.web;

import java.text.ParseException;
import java.util.List;

import jodd.datetime.JDateTime;

import com.wlcj.util.RedisUtil;
import com.wlcj.www.model.data.Data;
import com.wlcj.www.model.main.Content;
import com.wlcj.www.model.main.Friendlink;
import com.wlcj.www.model.main.Penster;
import com.wlcj.www.model.platform.Platform;
import com.wlcj.www.service.TopicService;
import com.wlcj.www.util.DataUtil;

public class IndexNewAction extends BaseAction {
	private TopicService topicService = s(TopicService.class);
	public void index() throws ParseException {
		int[] guanggaoweiids = new int[]{2420,2421,2422,2423,2713,2424};
		List<Content> guanggaowei = RedisUtil.get("guanggaoweilist");
		if(guanggaowei  == null){
			guanggaowei = Content.dao.getListByIds(guanggaoweiids);
		}
		List<Friendlink> flist =  RedisUtil.get("friendlinklist");
		if(flist == null || flist.size() == 0){
			flist = Friendlink.dao.getList();
		}
//		List<Content> pingtaigonggaolist = Content.dao.getListByChannelIds(new int[]{98,104}, 0,5);
		setAttr("flist", flist);
		setAttr("flistSize", flist.size());
		setAttr("guanggaowei", guanggaowei);
		renderJsp("index.jsp");
	}

	public void getGunDong() {
		int type_id = getParaToInt("type_id");
		int count = getParaToInt("count");
		List<Content> list = RedisUtil.get("gundonglist");
		if(list == null || list.size() == 0){
			list = Content.dao.getListByTypeId(type_id, 0, count);
		}
		setAttr("list", list);
		setAttr("count", list.size());
		renderJsp("gundong.jsp");
	}

	public void gundongright() {
		int type_id = getParaToInt("type_id");
		int count = getParaToInt("count");
		List<Content> list = RedisUtil.get("gundongrightlist");
		if(list == null || list.size() == 0){
			list = Content.dao.getListByTypeId(type_id, 0, count);
		}
		setAttr("list", list);
		setAttr("count", list.size());
		renderJsp("gundongright.jsp");
	}

	public void toutiaolist() {
		int type_id = getParaToInt("type_id");
		int count = getParaToInt("count");
		List<Content> list = RedisUtil.get("toutiaolist"); 
		if(list == null || list.size() == 0){
			list = Content.dao.getTouTiaoListByTypeId(type_id, 0,count);
			for (int i = 0; i < list.size(); i++) {
				Content c =(Content)list.get(i);
				c.set("sort_date", DataUtil.timeTop(String.valueOf(c.get("sort_date"))));
				list.set(i, c);
			}
		}
		setAttr("list", list);
		setAttr("count", list.size());
		renderJsp("toutiaolist.jsp");
	}
	public void pingtaigonggao(){
		int channel_id = getParaToInt("channel_id");
		int count = getParaToInt("count");
		List<Content> list = RedisUtil.get("pingtaigonggaolist");  
		if(list == null || list.size() == 0){
			list = Content.dao.getListByChannelId(channel_id, 0,count);
		}
		setAttr("list", list);
		renderJsp("pingtaigonggao.jsp");
	}
	public void zhongguancunjinrong(){
		int channel_id = getParaToInt("channel_id");
		int count = getParaToInt("count");
		List<Content> list = RedisUtil.get("zhongguancunjinronglist");  
		if(list == null || list.size() == 0){
			list = Content.dao.getListByChannelId(channel_id, 0,count);
		}
		setAttr("list", list);
		renderJsp("zhongguancun.jsp");
	}
	public void dalaofangtan(){
		int channel_id = getParaToInt("channel_id");
		int count = getParaToInt("count");
		List<Content> list = RedisUtil.get("dalaofangtanlist");  
		if(list == null || list.size() == 0){
			list = Content.dao.getListByChannelId(channel_id, 0,count);
			for (int i = 0; i < list.size(); i++) {
				Content c =(Content)list.get(i);
				c.set("sort_date", String.valueOf(c.get("sort_date")).substring(2, 10).replaceAll("-", "/"));
				list.set(i, c);
			}
		}
		setAttr("list", list);
		renderJsp("dalaofangtan.jsp");
	}
	public void weilaiwangping(){
		List<Content> weilaiwangpingList = RedisUtil.get("weilaiwangpingList");
		if(weilaiwangpingList == null || weilaiwangpingList.size() == 0){
			weilaiwangpingList = Content.dao.getListByChannelId(82, 0,6);
			for (int i = 0; i < weilaiwangpingList.size(); i++) {
				Content c =(Content)weilaiwangpingList.get(i);
				c.set("sort_date", String.valueOf(c.get("sort_date")).substring(2, 10).replaceAll("-", "/"));
				weilaiwangpingList.set(i, c);
			}
		}
		List<Content> wangqingjianceList = RedisUtil.get("wangqingjianceList");
		if(wangqingjianceList == null || wangqingjianceList.size() == 0){
			wangqingjianceList = Content.dao.getListByChannelId(79, 0,5);
		}
		List<Content> manhuajinrongList = RedisUtil.get("manhuajinrongList");
		if(manhuajinrongList == null || manhuajinrongList.size() == 0){
			manhuajinrongList = Content.dao.getListByChannelId(40, 0,9);
		}
		setAttr("weilaiwangpingList", weilaiwangpingList);
		setAttr("wangqingjianceList", wangqingjianceList);
		setAttr("manhuajinrongList", manhuajinrongList);
		renderJsp("weilaiwangping.jsp");
	}
	public void zhuanlan(){
		List<Penster> plist = RedisUtil.get("zhuanlanplist");
		if(plist== null || plist.size() == 0){
			plist = Penster.dao.getListByRecommend(0, 4);
		}
		int channel_id = getParaToInt("channel_id");
		List<Penster> clist = RedisUtil.get("zhuanlanclist");
		if(clist == null || clist.size() == 0){
			clist = Penster.dao.getListByChannelId(channel_id,0, 9);
		}
		setAttr("plist", plist);
		setAttr("clist", clist);
		renderJsp("zhuanlan.jsp");
	}
	public void caizhiyuedu(){
		int channel_id = getParaToInt("channel_id");
		int count = getParaToInt("count");
		List<Content> list = RedisUtil.get("caizhiyuedulist");
		if(list == null || list.size() == 0){
			list = Content.dao.getListByChannelId(channel_id, 0,count);
		}
		setAttr("list", list);
		renderJsp("caizhiyuedu.jsp");
	}
	public void pingtaidongtai(){
		List<Content> list = RedisUtil.get("pingtaidongtailist");
		if(list == null || list.size() == 0){
			list = Content.dao.getListByChannelIds(new int[]{98,104}, 0,8);
			for (int i = 0; i < list.size(); i++) {
				Content c =(Content)list.get(i);
				c.set("sort_date", String.valueOf(c.get("sort_date")).substring(2, 10).replaceAll("-", "/"));
				list.set(i, c);
			}
		}
		setAttr("list", list);
		renderJsp("pingtaidongtai.jsp");
	}
	public void pingtaishuju(){
	//	String type = DataUtil.createTypeStr(1);//"2014-09-09/2014-09-09";//DataUtil.createTypeStr(1);
		List<Platform> list = Platform.dao.getIndexList();
		setAttr("list", list);
		renderJsp("pingtaishuju.jsp");
	}
	/**
	 * 平台数据报表
	 */
	public void platformDataBaobiao(){
	//date_format(data_date,' %m/%d') 
	   List<Data> bigDate = Data.dao.find("select max(data_date) from wd_new_data");
		List<Data> list = Data.dao.find(" select  volume , data_date from wd_new_data  where  platform_id = ? and  data_date>= ? limit 0,10",getParaToInt("platform_id"),new JDateTime(bigDate.get(0).get("max(data_date)").toString()).addDay(-10).toString("YYYY-MM-DD")); 
		renderJson(list);
		
	}
	public void wangqingju(){
		setAttr("wqjList", topicService.getWqjList());
		renderJsp("wangqingju.jsp");
	}
	public void bbs(){
		setAttr("bbsList", topicService.getBbsList());
		renderJsp("bbs.jsp");
	}
	
}
